home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 4.5 KB | 239 lines | [TEXT/CWIE] |
- // MenuItem.cp
-
- #ifndef MenuItem_h
- #include "MenuItem.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- bool MenuItem::Enabled() const
- {
- Assert( CanEnableIndividually() );
- return ( (*menu)->enableFlags & (1L << item) ) != 0;
- }
-
- void MenuItem::Enable()
- {
- Assert( CanEnableIndividually() );
- if ( !Enabled() )
- EnableItem( menu, item );
- Assert( Enabled() );
- }
-
- void MenuItem::Disable()
- {
- Assert( CanEnableIndividually() );
- if ( Enabled() )
- DisableItem( menu, item );
- Assert( !Enabled() );
- }
-
- void MenuItem::SetEnabled( bool b )
- {
- Assert( b == !!b );
- if ( b == Enabled() )
- return;
-
- if ( b )
- EnableItem( menu, item );
- else
- DisableItem( menu, item );
-
- Assert( b == Enabled() );
- }
-
- void MenuItem::SetText( ConstPString string )
- {
- Assert( string.Length() > 0 );
- if ( string[0] != '-' )
- SetMenuItemText( menu, item, string );
- else
- {
- // We slip in a null character to avoid this item
- // showing up as a divider.
- String255 edited( "\p\0" );
- edited += string;
- SetMenuItemText( menu, item, edited );
- }
- }
-
- MenuItem::SpecialEffect MenuItem::Effect() const
- {
- int16 key;
- GetItemCmd( menu, item, &key );
- Assert( 0 <= key && key < maxuint8 );
- return ( key < int16( commandKey ) )
- ? SpecialEffect( key )
- : commandKey;
- }
-
- bool MenuItem::CanSetEffect( SpecialEffect effect ) const
- {
- Assert( effect > noEffect && effect < commandKey );
- int16 key;
- GetItemCmd( menu, item, &key );
- Assert( 0 <= key && key < maxuint8 );
- return key == 0 || key == int16( effect );
- }
-
- bool MenuItem::CanClearEffect( SpecialEffect effect ) const
- {
- Assert( effect > noEffect && effect < commandKey );
- int16 key;
- GetItemCmd( menu, item, &key );
- Assert( 0 <= key && key < maxuint8 );
- return key == int16( effect );
- }
-
- bool MenuItem::CanSetCommandKey() const
- {
- int16 key;
- GetItemCmd( menu, item, &key );
- Assert( 0 <= key && key < maxuint8 );
- return key == 0 || key >= int16( commandKey );
- }
-
- void MenuItem::SetEffect( SpecialEffect effect )
- {
- Assert( CanSetEffect( effect ) );
- SetItemCmd( menu, item, int16( effect ) );
- }
-
- void MenuItem::ClearEffect( SpecialEffect effect )
- {
- Assert( CanClearEffect( effect ) );
- SetItemCmd( menu, item, 0 );
- }
-
- ::Style MenuItem::Style() const
- {
- ::Style result;
- GetItemStyle( menu, item, &result );
- return result;
- }
-
- uint8 MenuItem::Mark() const
- {
- if ( HasSubmenu() )
- return noMark;
-
- int16 result;
- GetItemMark( menu, item, &result );
- Assert( 0 <= result && result < maxuint8 );
- return result;
- }
-
- void MenuItem::SetMark( uint8 mark )
- {
- Assert( !HasSubmenu() );
- SetItemMark( menu, item, mark );
- }
-
- uint8 MenuItem::CommandKey() const
- {
- int16 key;
- GetItemCmd( menu, item, &key );
- Assert( 0 <= key && key < maxuint8 );
- return ( key < int16( commandKey ) ) ? 0 : key;
- }
-
- void MenuItem::SetCommandKey( uint8 key )
- {
- Assert( CanSetCommandKey() );
- SetItemCmd( menu, item, key );
- }
-
- void MenuItem::RemoveCommandKey()
- {
- Assert( HasCommandKey() );
- SetItemCmd( menu, item, 0 );
- }
-
- MenuID MenuItem::Submenu() const
- {
- if ( !HasSubmenu() )
- return 0;
-
- int16 result;
- GetItemMark( menu, item, &result );
- Assert( 0 <= result && result < maxuint8 );
- return MenuID( result );
- }
-
- void MenuItem::SetSubmenu( MenuID id )
- {
- Assert( Mark() == noMark );
- Assert( 1 <= id && id <= 235 ); // 236-255 are reserved for DAs
- SetItemMark( menu, item, id );
- SetEffect( submenu );
- }
-
- void MenuItem::RemoveSubmenu()
- {
- ClearEffect( submenu );
- SetItemMark( menu, item, 0 );
- }
-
- uint8 MenuItem::ScriptCode() const
- {
- if ( !HasScriptCode() )
- return 0;
-
- int16 result;
- GetItemIcon( menu, item, &result );
- Assert( 0 <= result && result < maxuint8 );
- return result;
- }
-
- void MenuItem::SetScriptCode( uint8 id )
- {
- Assert( !HasIcon() );
- SetItemIcon( menu, item, id );
- SetEffect( script );
- }
-
- void MenuItem::RemoveScriptCode()
- {
- ClearEffect( script );
- SetItemIcon( menu, item, 0 );
- }
-
- bool MenuItem::HasIcon() const
- {
- if ( HasScriptCode() )
- return false;
-
- int16 icon;
- GetItemIcon( menu, item, &icon );
- Assert( 0 <= icon && icon < maxuint8 );
- return icon != 0;
- }
-
- int16 MenuItem::Icon() const
- {
- if ( !HasScriptCode() )
- return 0;
-
- int16 icon;
- GetItemIcon( menu, item, &icon );
- Assert( 0 <= icon && icon < maxuint8 );
- return ( icon == 0 )
- ? 0
- : int16( icon ) + 256;
- }
-
- void MenuItem::SetIcon( int16 id )
- {
- Assert( !HasScriptCode() );
- Assert( id > 256 );
- Assert( id < 512 );
- SetItemIcon( menu, item, id - 256 );
- }
-
- void MenuItem::RemoveIcon()
- {
- Assert( !HasScriptCode() );
- SetItemIcon( menu, item, 0 );
- }
-